"use client";
import { Result } from "antd";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";

/**
 * 未找到页面
 * @constructor
 */
const NotFound = () => {
  const [countDown, setCountDown] = useState(3);
  const router = useRouter();

  useEffect(() => {
    const time = setTimeout(() => {
      if (countDown === 1) {
        clearTimeout(time);
        router.back();
        return;
      }
      setCountDown(countDown - 1);
    }, 1000);
    return () => {
      clearTimeout(time);
    };
  }, [countDown, router]);

  return (
    <Result
      title="404"
      status="404"
      subTitle={`抱歉，你访问的页面不存在，即将返回上一页，${countDown}秒后自动返回`}
      style={{
        fontWeight: "bold",
        fontSize: "2rem",
      }}
    />
  );
};

export default NotFound;
